<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
    mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
    components: {
        // SelectImageRadio: async () =>
        //     Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectImageRadio()),
    },
    data() {
        return {
            appWindow: window,
            form: {
                // has_option: false,
                // is_independent: true,
                // join_status: true,
                // name: "",
            },

            // 页面接口地址
            apiUrl: {
                create: "admin/category/add",
                update: "admin/category/edit",
                detail: "plugin/distribution/backend/goods/show",
            },
            levelCommission: null,

            levelValue1: "",
            levelValue2: "",

            levelValue3: "",
            levelValue4: "",

            levelValue5: "",
            levelValue6: "",

            visible1: false,
            visible2: false,
            visible3: false,
        };
    },
    methods: {
        // 批量操作
        batch1() {
            if(this.form.has_option == true) {
                this.form.commission_rule.forEach(element => {
                    element.rule.forEach(item => {
                        item.commission_1.rate = this.levelValue1;
                        item.commission_1.money = this.levelValue2;
                    });
                });
            }else {
                this.form.commission_rule.forEach(element => {
                    element.rule.commission_1.rate = this.levelValue1;
                    element.rule.commission_1.money = this.levelValue2;
                });
            }
            this.visible1 = false;
        },
        batch2() {
            if(this.form.has_option == true) {
                this.form.commission_rule.forEach(element => {
                    element.rule.forEach(item => {
                        item.commission_2.rate = this.levelValue3;
                        item.commission_2.money = this.levelValue4;
                    });
                });
            }else {
                this.form.commission_rule.forEach(element => {
                    element.rule.commission_2.rate = this.levelValue3;
                    element.rule.commission_2.money = this.levelValue4;
                });
            }
            this.visible2 = false;
        },
        batch3() {
            if(this.form.has_option == true) {
                this.form.commission_rule.forEach(element => {
                    element.rule.forEach(item => {
                        item.commission_3.rate = this.levelValue5;
                        item.commission_3.money = this.levelValue6;
                    });
                });
            }else {
                this.form.commission_rule.forEach(element => {
                    element.rule.commission_3.rate = this.levelValue5;
                    element.rule.commission_3.money = this.levelValue6;
                });
            }
            this.visible3 = false;
        },

        async setCommission() {
            let res = await this.$vFN.Http.post({
                url: "plugin/distribution/backend/settings/base/get",
            }, window);
            this.levelCommission = res.data.level;
        },
        async sum() {
            let res = await this.$vFN.Http.post({
                url: "plugin/distribution/backend/goods/setCommission",
                data: {
                    product_id: this.product_id,
                    is_independent: this.form.is_independent,
                    join_status: this.form.join_status,
                    has_option: this.form.has_option,
                    commission_rule: this.form.commission_rule,
                    default_rule: this.form.default_rule,
                }
            },window);
            if(res.code == 200) {
                this.onSuccess();
                this.$vFN.Tools.messageSuccess("操作成功");
                this.mixinEdit_editVisible = false;
            }
        },
        // 获取详情
        async getData() {
            let res = await this.$vFN.Http.post({
                url: this.apiUrl.detail,
                data: {
                    product_id: this.product_id,
                }
            },window)
            this.form = res.data;
        },
        // 初始化
        async init() {
            // 初始化数据
            // await this.mixinEdit_editBoxInit({
            //     model: "form",
            //     product_id: this.id,
            // });
            // 显示窗口
            this.mixinEdit_editVisible = true;
            this.getData();
            this.setCommission();
        },

        cacel() {
            this.mixinEdit_editVisible = false;
        },
        onSuccess() {},

    },
    mounted() {
        this.init();
    },
    activated() {},
};
</script>